package com.macasa.panel.entity.impl;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.AbstractModel;
import com.macasa.panel.entity.api.IPureFtpdService;
import com.macasa.panel.entity.api.IPureFtpdServiceUser;

@Entity
@Table(name = "pure_ftpd_service_user")
@SequenceGenerator(name = "PureFtpdServiceUser_SEQ", sequenceName = "PureFtpdServiceUserIdSeq", initialValue = 1)
@Getter
@Setter
@ToString
public class PureFtpdServiceUser extends AbstractModel<Integer> implements IPureFtpdServiceUser {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= 8408548077872259244L;

	@Id
	@Column(name = "pure_ftpd_service_user_id", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "PureFtpdServiceUser_SEQ")
	private Integer				id;

	@Column(name = "pure_ftpd_user", nullable = false)
	private String				pureFtpdUser;

	@Column(name = "pure_ftpd_password", nullable = false)
	private String				pureFtpdPassword;

	@Column(name = "disk_root", nullable = false)
	private String				diskRoot;

	@Column(name = "disk_quota", nullable = false)
	private Integer				diskQuota;

	@Column(name = "ip_address_access", nullable = false)
	private String				ipAddressAccess;

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, targetEntity = com.macasa.panel.entity.impl.PureFtpdService.class)
	@JoinColumn(name = "fk_pure_ftpd_service_id", nullable = false)
	private IPureFtpdService	pureFtpdService;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof PureFtpdServiceUser)) {
			return false;
		}

		final PureFtpdServiceUser other = CastHelpers.cast(obj, PureFtpdServiceUser.class);

		return Objects.equal(this.id, other.id) && Objects.equal(this.pureFtpdUser, other.pureFtpdUser)
				&& Objects.equal(this.pureFtpdPassword, other.pureFtpdPassword) && Objects.equal(this.diskRoot, other.diskRoot)
				&& Objects.equal(this.diskQuota, other.diskQuota) && Objects.equal(this.ipAddressAccess, other.ipAddressAccess)
				&& Objects.equal(this.pureFtpdService, other.pureFtpdService);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.id, this.pureFtpdUser, this.pureFtpdPassword, this.diskRoot, this.diskQuota, this.ipAddressAccess, this.pureFtpdService);
	}
}
